using System;
using Microsoft.SmallBasic.Library;
using SmallBasicFun.Quizes;

namespace SmallBasicFun
{
	[SmallBasicType]
	public class Quiz
	{
		public static Question[] questions = new Question[6];
		private static IQuiz quiz;


		public static void DisplayScores(int numberOfQuestions, int x)
		{
			GraphicsWindow.BrushColor = Colors.CornflowerBlue;
			ProgramWindow.DrawText("You Scored " + GetAmountCorrect(numberOfQuestions) + " out of " + numberOfQuestions, x, 60);

			for (int i = 0; i < numberOfQuestions; i++)
			{
				DisplayResults(i, x);
			}
		}

		private static int GetAmountCorrect(int numberOfQuestions)
		{
			int count = 0;
			for (int i = 0; i < numberOfQuestions; i++)
			{
				if (questions[i].Result)
				{
					count++;
				}
			}
			return count;
		}

		private static void DisplayResults(int number, int x)
		{
			GraphicsWindow.BrushColor = Colors.LightBlue;
			ProgramWindow.DrawText("Question " + (number + 1) + " - ", x, 80 + (20*number));
			GraphicsWindow.BrushColor = questions[number].Result ? Colors.ForestGreen : Colors.Red;
			ProgramWindow.DrawText(questions[number].Result ? "Pass" : "Fail", x + 80, 80 + (20*number));
		}

		public static void LoadQuestions(SmallBasicCallback callback, params string[] questionNames)
		{
			for (int i = 0; i < questionNames.Length; i++)
			{
				questions[i] = new Question(callback.Method.DeclaringType, callback.Target, questionNames[i]);
			}
		}

		#region Quiz Starters

		public static event SmallBasicCallback StartDemoQuizAt
		{
			add
			{
				LoadQuestions(value, "question1");
				new DemoQuiz().StartTest();
			}

			remove { }
		}

		public static event SmallBasicCallback StartSquareQuizAt
		{
			add
			{
				LoadQuestions(value, "question1", "question2", "question3", "question4");
				new SquareQuiz().StartTest();
			}

			remove { }
		}

		public static event SmallBasicCallback StartHouseQuizAt
		{
			add
			{
				LoadQuestions(value, "question1", "medium", "large", "movethelength", "turnthecorner", "drawaside");
				new HouseQuiz().StartTest();
			}

			remove { }
		}

		public static event SmallBasicCallback StartPentagonQuizAt
		{
			add
			{
				ColorWheel.SetWheel(new Wheel<Primitive>());
				LoadQuestions(value, "thread", "question2", "question3", "question4");
				quiz = new PentagonCrazyQuiz();
				quiz.StartTest();
			}

			remove { }
		}

		public static void Stitch()
		{
			((PentagonCrazyQuiz)quiz).Stitch();
		}
		public static event SmallBasicCallback StartBubbleQuizAt
		{
			add
			{
				LoadQuestions(value, "move", "question2", "question3", "question4", "question5");
				quiz = new BubbleQuiz();
				quiz.StartTest();
			}

			remove { }
		}


		public static void DoMovement()
		{
			((BubbleQuiz)quiz).DoMovement();
		}

		public static event SmallBasicCallback StartHighLowQuizAt
		{
			add
			{
				LoadQuestions(value, "question1", "question2", "question3", "question4");
				quiz = new HighLowQuiz();
				quiz.StartTest();
			}

			remove { }
		}
		public static event SmallBasicCallback StartSpiderQuizAt
		{
			add
			{
				LoadQuestions(value, "question1", "circlearound", "grow", "shrink", "expand");
				quiz = new SpiderQuiz();
				quiz.StartTest();
			}

			remove { }
		}

		public static void Circle()
		{
			((SpiderQuiz)quiz).Circle();
			
		}

		public static void Adjust()
		{
			((SpiderQuiz)quiz).Adjust();
		}
		public static event SmallBasicCallback StartTreeQuizAt
		{
			add
			{
			LoadQuestions(value, "question1", "decreaseturn", "setninety", "anglefive");
				quiz = new TreeQuiz();
				quiz.StartTest();
			}

			remove { }
		}
		public static event SmallBasicCallback StartBackWordsExceriseAt
		{
			add
			{
				LoadQuestions(value, "reverseWord");
				//quiz = new BackWordsExercise();
				//quiz.StartTest();
			}

			remove { }
		}
		
		#endregion
	}
}